class T_Box_Seekable;     //
class T_Box_Seek_Manager; //

#ifndef T_BOX_SEEK_MANAGER_H
#define T_BOX_SEEK_MANAGER_H

#include "stable.h"

class T_Box_Seekable
{
public:
    virtual qint64 seekMe(T_Box_Seek_Manager *a_seek_mgr, qint64 a_msec) = 0;
};

class T_Box_Seek_Manager
    : public T_LockedObject
    , public T_SlimpleWaitCondition
    , public T_AutoRunClock //FIXME: hide this
{
    Q_OBJECT
public:
    explicit T_Box_Seek_Manager()
        : m_duration(0)
        , m_max_timing(0)
    {
    }
    T_Clock *timeline()
    {
        return &m_stopwatch;
    }
    qint64 mediaDuration()
    {
        return m_duration;
    }
    void setContentDuration(qint64 a_duration)
    {
        m_duration = a_duration;
    }
    int pendingRequest();
    void enqueueRequest(int a_timing);
    int dequeueRequest();
    qint64 maxTiming();
    void registerTiming(qint64 a_timing);
    qint64 seekableDuration();
    qint64 endlessDuration(qint64 a_timing);
    void addSeekable(T_Box_Seekable *a_seekable);
    qint64 seek(qint64 a_msec);
    bool isCriticalTime()
    {
        return (this->T_AutoRunClock::elapsed()<700);
    }
protected:
    //FIXME: hide these
    T_Clock m_stopwatch;
    qint64 m_duration;
    T_Queue<int, -1> m_request_queue;
    T_Atomic m_request_atomic;
    qint64 m_max_timing;
    QList<T_Box_Seekable *> m_seekable_list; //FIXME: use QPointer<QObject>
};

#endif // T_BOX_SEEK_MANAGER_H
